﻿using DiffuseEnjoyIdle.IRepository;
using DiffuseEnjoyIdle.IService;
using Microsoft.Extensions.Logging;
using NeoSmart.AsyncLock;

namespace DiffuseEnjoyIdle.Service
{
    public class UserService : IUserService
    {
        private readonly ILogger<UserService> _logger;
        private readonly IUserRepository _userRepository;
        private static string name = "sd";
        private readonly AsyncLock _mutex;
        public UserService(ILogger<UserService> logger, IUserRepository userRepository)
        {
            _logger = logger;
            _userRepository = userRepository;
            _mutex = new AsyncLock();
        }

        public async Task<string> Test()
        {
            var s = default(DateTime);
            var t = string.Format("c", 131);
            var id = Guid.NewGuid();
            _logger.LogInformation($"进入定时任务，name:{name},id:{id},开始时间:{DateTime.Now}");
            using (await _mutex.LockAsync())
            {
                name="dc"+id;
                _logger.LogInformation($"定时任务完成,name:{name},id:{id},结束时间:{DateTime.Now}");
              
            }

            return "12314212313";

        }
    }
}